/*
 * Copyright (c) 2005, 2014 vacoor
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package org.vacoor.nothing.demo.jackson.databinding;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.Date;

/**
 */
public class JacksonDataBindingDemo {
    ObjectMapper mapper;
    User u;

    public void before() {
        mapper = new ObjectMapper();
        u = new User();
        u.setId(1);
        User.Name n = new User.Name();
        n.setFirst("FirstName");
        n.setLast("LastName");
        u.setName(n);
        u.setAge(22);
        u.setBirth(new Date());
        u.setAddr("Address");

        User parent = new User();
        User.Name pname = new User.Name();
        parent.setId(2);
        pname.setFirst("ParentFirstName");
        pname.setLast("ParentLastName");
        parent.setBirth(new Date());
        parent.setAddr("PADDR");

        u.setParent(parent);
    }

    public void testDataBinding() throws JsonProcessingException {
        String json = mapper.writeValueAsString(u);
        System.out.println(json);
    }
}
